home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Examples / Table / Include / TblPart.h < prev    next >
Encoding:
Text File  |  1995-11-08  |  6.9 KB  |  241 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                TblPart.h
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef TBLPART_H
  11. #define TBLPART_H
  12.  
  13. // ----- TablePart Includes -----
  14.  
  15. #ifndef TBLDEF_H
  16. #include "TblDef.h"
  17. #endif
  18.  
  19. // ----- ODF Includes -----
  20.  
  21. #ifndef FWPARTNG_H
  22. #include "FWPartng.h"
  23. #endif
  24.  
  25. #ifndef FWMNUITM_H
  26. #include "FWMnuItm.h"
  27. #endif
  28.  
  29. #ifndef FWPOINT_H
  30. #include "FWPoint.h"
  31. #endif
  32.  
  33. #ifndef FWFXMATH_H
  34. #include "FWFxMath.h"
  35. #endif
  36.  
  37. //==============================================================================
  38. //    Constants
  39. //==============================================================================
  40.  
  41. const ODULong kMaxCols = 32;
  42. const ODULong kMaxRows = 32;
  43.  
  44. // ----- Default size of cell -----
  45. const FW_CFixed kDefaultCellWidth  = FW_IntToFixed(80);
  46. const FW_CFixed kDefaultCellHeight = FW_IntToFixed(80);
  47.  
  48. // ----- Hit-test constants -----
  49. const FW_CFixed kPenWidth  = FW_IntToFixed(1);
  50. const FW_CFixed kPenHeight = FW_IntToFixed(1);
  51.  
  52. const FW_CFixed kVMargin = FW_IntToFixed(4); // width of vertical line margin
  53. const FW_CFixed kHMargin = FW_IntToFixed(4); // height of horz. line margin
  54.  
  55. const FW_CFixed kBorderWidth  = kPenWidth;
  56. const FW_CFixed kBorderHeight = kPenHeight;
  57.  
  58. typedef short ETableLoc;
  59. const ETableLoc kTLNone = -1;
  60. const ETableLoc kTLCell = 0;
  61. const ETableLoc kTLLeftBorder = 1;
  62. const ETableLoc kTLRightBorder = 2;
  63. const ETableLoc kTLTopBorder = 4;
  64. const ETableLoc kTLBottomBorder = 8;
  65.  
  66. // ----- Menus -----
  67.  
  68. #ifdef FW_BUILD_WIN
  69. const short kEmbedMenu = 6;
  70. #endif
  71.  
  72. // ----- Commands -----
  73. const ODCommandID cHideShowGrid    = FW_kFirstUserCommandID;
  74.  
  75. //==============================================================================
  76. //    CCell Class
  77. //==============================================================================
  78.  
  79. class CCell
  80. {
  81. public:
  82.     CCell() {fX = 0; fY = 0;}
  83.     CCell(short x, short y) {fX = x; fY = y;}
  84.     CCell(const CCell& other) {fX = other.fX; fY = other.fY;} 
  85.     ~CCell() {}
  86.     
  87.     CCell& operator=(const CCell& other) {fX = other.fX; fY = other.fY; return *this;}
  88.     
  89.     FW_Boolean operator==(const CCell& other) const {return other.fX == fX && other.fY == fY;}
  90.     FW_Boolean operator!=(const CCell& other) const {return other.fX != fX || other.fY != fY;}
  91.     
  92. public:
  93.     short    fX;
  94.     short    fY;
  95. };
  96.  
  97. //==============================================================================
  98. //    Forward declarations
  99. //==============================================================================
  100.  
  101. #if FW_LIB_EXPORT_PRAGMAS
  102. #pragma import on
  103. #endif
  104. class FW_CLASS_ATTR FW_CDropCommand;
  105. class FW_CLASS_ATTR FW_CMenuBar;
  106. #if FW_LIB_EXPORT_PRAGMAS
  107. #pragma import off
  108. #endif
  109.  
  110. class FW_CLASS_ATTR CTableFrame;
  111. class FW_CLASS_ATTR CTableProxy;
  112. class FW_CLASS_ATTR CTableSelection;
  113. class FW_CLASS_ATTR CTableLinkManager;
  114.  
  115. //==============================================================================
  116. //    class CTablePart
  117. //==============================================================================
  118.  
  119. class FW_CLASS_ATTR CTablePart : public FW_CEmbeddingPart
  120. {
  121.     friend class CTableLinkManager;
  122.  
  123.   public:
  124.     static const ODValueType kPartKind;
  125.     static const ODValueType kPartUserName;
  126.     
  127. //----------------------------------------------------------------------------------------
  128. //    Initialization/Destruction
  129. //
  130.   public:
  131.     CTablePart(ODPart* odPart);
  132.     virtual ~CTablePart();
  133.  
  134. //----------------------------------------------------------------------------------------
  135. //    Inherited API
  136. //
  137.   public:
  138.     virtual void            Initialize(Environment* ev);
  139.             
  140.     // ----- Content I/O -----
  141.     virtual void            ExternalizeContent(Environment *ev, ODStorageUnit* storageUnit, FW_CCloneInfo* cloneInfo);
  142.     virtual void            InternalizeContent(Environment* ev, ODStorageUnit* storageUnit, FW_CCloneInfo* cloneInfo);
  143.     
  144.     // ----- Create Stuff -----
  145.     virtual FW_CFrame*         NewFrame(Environment* ev, 
  146.                                      ODFrame* odFrame, 
  147.                                      FW_CPresentation* presentation,
  148.                                      FW_Boolean fromStorage);
  149.                                         
  150.     // ----- Linking Support -----
  151.     virtual void        ContentUpdated(Environment* ev,
  152.                                        FW_CFrame* frame, 
  153.                                        ODUpdateID id);    // Override
  154.     
  155.     virtual FW_Boolean    DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, FW_Boolean hasMenuFocus, FW_Boolean isRoot);
  156.  
  157. //----------------------------------------------------------------------------------------
  158. //    New API
  159. //
  160.   public:
  161.       // ----- Menu Bar Initialization -----
  162.     void InitializeMenuBar(Environment *ev, FW_CMenuBar *menuBar);
  163.  
  164.     // ----- Getters/setters -----
  165.     const CCell&        GetSize() const;
  166.     FW_CFixed            GetWidth (short c) const;
  167.     FW_CFixed            GetHeight(short r) const;
  168.     void                SetWidth (short c, FW_CFixed w);
  169.     void                SetHeight(short r, FW_CFixed h);
  170.     
  171.     // ----- For point on border, returned cell is above and to left -----
  172.     ETableLoc            HitTest(Environment* ev, 
  173.                                 const CTableFrame* frame,
  174.                                 const FW_CPoint& where,
  175.                                 CCell& cell) const;
  176.  
  177.     // ----- Coordinates from cell -----
  178.     FW_CFixed            FindLeft(short col) const;
  179.     FW_CFixed            FindTop (short row) const;
  180.     void                FindRect(const CCell& cell,
  181.                                  FW_CRect& rect)  const;
  182.  
  183.     CTableProxy*        CellToProxy(Environment* ev, const CCell& cell) const;
  184.  
  185.     // ----- Resizing -----
  186.     void                Resize(Environment* ev, 
  187.                                 const CCell& cell, 
  188.                                 ETableLoc tl, 
  189.                                 const FW_CPoint& delta);
  190.                                           
  191.     // ----- Add/Remove proxys -----
  192.     void                AddProxy(CTableProxy* proxy);
  193.     void                RemoveProxy(CTableProxy* proxy);
  194.     
  195.     // ----- Linking Support -----
  196.     FW_CLinkManager*    NewLinkManager(Environment *ev);    // Override
  197.  
  198.     FW_Boolean            IsLinkSelected(Environment* ev);
  199.  
  200.     CTableSelection*    GetTableSelection(Environment* ev);
  201.  
  202.     void                RegisterSubscribers(Environment* ev);
  203.     FW_Boolean            ShowLinkInfo(Environment* ev, FW_CFrame* frame);
  204.  
  205.     void                AboutToClearCell(Environment* ev, const CCell& cell);
  206.     void                ChangeFrameStatus(Environment* ev, const CCell& cell, ODLinkStatus newStatus);
  207.     void                ProxyMoved(Environment* ev, const CCell& fromCell, const CCell& toCell);
  208.  
  209. //----------------------------------------------------------------------------------------
  210. //    Data Members
  211. //
  212.   private:
  213.     FW_CPrivOrderedCollection*    fProxys;
  214.     
  215.     FW_CPresentation*             fTablePresentation;
  216.     
  217.     // ----- Current size in memory -----
  218.     CCell                        fCells;
  219.     
  220.     // ----- Width and height of cells -----
  221.     FW_CFixed                fWidth [kMaxCols];
  222.     FW_CFixed                fHeight[kMaxRows];
  223.  
  224.     CTableLinkManager*            fTableLinkManager;
  225.     FW_Boolean                    fSubscribersRegistered;
  226. };
  227.  
  228. //========================================================================================
  229. //    CTablePart Inlines
  230. //========================================================================================
  231.  
  232. //----------------------------------------------------------------------------------------
  233. //    CTablePart::GetSize
  234. //----------------------------------------------------------------------------------------
  235. inline const CCell& CTablePart::GetSize() const
  236. {
  237.     return fCells;
  238. }
  239.  
  240. #endif
  241.